package com.stackfarm.controller;


import com.stackfarm.fvcommon.requests.SensorDatas;
import com.stackfarm.fvcommon.result.SensorData;
import com.stackfarm.fvservice.service.influxdb.SensorDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sensor")
@ResponseBody
@Api(tags = "获取检测器数据")
public class SensorDataController {
    @Autowired
    private SensorDataService sensorDataService;

    @ApiOperation("获取单一数据")
    @PostMapping("/getData")
    public SensorData getData(String type, Long startTime, Long endTime) {
        return sensorDataService.requestData(type, startTime, endTime);
    }

    @PostMapping("/getDatas")
    @ApiOperation(value = "获取所有数据")
    public List<SensorData> getDatas(@RequestBody SensorDatas sensorDatas) {
        return sensorDataService.requestDatas(sensorDatas.getStartTime(), sensorDatas.getEndTime(), sensorDatas.getType());
    }
}
